package com.mall.controller;

import com.mall.result.Result;
import com.mall.domain.dto.CategoryDTO;
import com.mall.domain.vo.CategoryVO;
import com.mall.service.CategoryService;
import com.mall.service.ItemService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类控制器
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/22 22:12
 */
@RestController
@RequestMapping("/category")
@RequiredArgsConstructor
@Tag(name = "分类管理", description = "分类管理相关接口")
public class CategoryController {

    private final CategoryService categoryService;

    /**
     * 添加分类
     * @return 添加成功
     */
    @PostMapping("/add")
    @Operation(summary = "添加分类")
    public Result<String> addCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.addCategory(categoryDTO);
        return Result.success("添加成功");
    }

    /**
     * 启用或者禁用分类
     * @param id 分类id
     * @param status 设置为什么状态
     * @return 启用或者禁用成功
     */
    @PostMapping("/status/{status}")
    @Operation(summary = "启用或者禁用分类")
    public Result<String> startOrStopCategory(Long id, @PathVariable Integer status) {
        categoryService.updateStatus(id, status);
        return Result.success("启用或者禁用成功");
    }

    /**
     * 查询分类列表
     * @return 分类列表
     */
    @GetMapping("/list")
    @Operation(summary = "查询分类列表")
    public Result<List<CategoryVO>> listCategory() {
        List<CategoryVO> categoryVOList = categoryService.listCategory();
        return Result.success(categoryVOList);
    }

    /**
     * 修改分类
     * @return 修改成功
     */
    @PutMapping("/update")
    @Operation(summary = "修改分类")
    public Result<String> updateCategory(@RequestBody CategoryDTO categoryDTO) {
        categoryService.updateCategory(categoryDTO);
        return Result.success("修改成功");
    }

    /**
     * 删除分类
     * @param id 分类id
     * @return 删除成功
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "删除分类")
    public Result<String> deleteCategory(@PathVariable Long id) {
        categoryService.deleteCategory(id);
        return Result.success("删除成功");
    }
}
